<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "sc";
$conn = new mysqli($servername, $username, $password,$dbname);
if (!$conn) {
    die("连接失败: " . mysqli_connect_error());
}
$sql1 = "CREATE TABLE Student (
id INT(8)  NOT NULL, 
name char(10),
birthday int(15),
gender char(2),
age int(3),
PRIMARY KEY(id)
)";
if (mysqli_query($conn, $sql1)) {
    echo "数据表 Student 创建成功";
} else {
    echo "创建数据表错误: " . mysqli_error($conn);
}
 echo "<br>";
$sql2 = "CREATE TABLE Lesson (
lesson_name varchar(8)  NOT NULL,
lesson_id INT(8)  NOT NULL,
advance_course varchar(8),
PRIMARY KEY(lesson_id)
)";
 
if (mysqli_query($conn, $sql2)) {
    echo "数据表 Lesson 创建成功";
} else {
    echo "创建数据表错误: " . mysqli_error($conn);
}
 echo "<br>";
$sql3 = "CREATE TABLE  Seletive_Lesson(
id INT(8) NOT NULL,
lesson_id INT(8) NOT NULL,
mark INT(3),
FOREIGN KEY(id) REFERENCES Student(id),
FOREIGN KEY(lesson_id) REFERENCES Lesson(lesson_id)
)";
 
if (mysqli_query($conn, $sql3)) {
    echo "数据表 Seletive_Lesson 创建成功";
} else {
    echo "创建数据表错误: " . mysqli_error($conn);
}

$conn->close();
?>